package com.ruoyi.hr.controller.hr.changemanage.virtualorganize;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.hr.service.PublicService;
import com.ruoyi.hr.service.changemanage.virtualorganize.VirtualOrganizeService;
import com.ruoyi.hr.service.entryexitmanage.retiremanage.RetireManageService;
import com.ruoyi.hr.util.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author yuanwei
 * @explain 员工虚拟组织管理
 * @date 2020/4/20
 */
@Controller
@RequestMapping("/changeManage/virtualOrganize")
public class VirtualOrganizeController extends BaseController {

    private String prefix = "hr/changemanage/virtualorganize";

    @Autowired
    private VirtualOrganizeService virtualOrganizeService;

    @Autowired
    private RetireManageService retireManageService;

    @Autowired
    private PublicService publicService;

    //加入
    @GetMapping("/join")
    public String virtualOrganizeJoin() {
        return prefix + "/virtualOrganizeJoin";
    }

    @PostMapping("/listJoin")
    @ResponseBody
    public TableDataInfo findVirtualJoinList(@RequestParam Map map) {
        return getDataTable(virtualOrganizeService.findVirtualJoinList(map));
    }

    @GetMapping("/addJoin")
    public String addJoin() {
        return prefix + "/addVirtualJoin";
    }

    @PostMapping("/addVirtualJoin")
    @ResponseBody
    public TableDataInfo addVirtualJoin(@RequestParam Map map) {
        return getDataTable(publicService.addPerson(map));
    }

    @PostMapping("/addVirtualJoinProcedure")
    @ResponseBody
    public BaseResult addVirtualJoinProcedure(String allEid, String allName) {
        return publicService.procedure(allEid, allName, "eSP_VirtualOrgAddEmp", "1");
    }

    @PostMapping("/procedure")
    @ResponseBody
    public BaseResult procedure(String allId, String allName, String procedure) {
        return publicService.procedure(allId, allName, procedure);
    }

    @GetMapping("/editJoin/{id}")
    public String editJoin(@PathVariable("id") String id, ModelMap mmap) {
        mmap.put("editJoin", virtualOrganizeService.findVirtualJoin(id));
        mmap.put("virtualDep", virtualOrganizeService.findVirtualDep());
        mmap.put("virtualJob", virtualOrganizeService.findVirtualJob());
        return prefix + "/editVirtualJoin";
    }

    @PostMapping("/editJoin")
    @ResponseBody
    public AjaxResult editJoin(@RequestParam Map map) {
        return toAjax(virtualOrganizeService.updateVirtualJoin(map));
    }

    @PostMapping("/removeJoin")
    @ResponseBody
    public AjaxResult removeJoin(String ids) {
        int num = virtualOrganizeService.removeVirtualJoin(ids);
        if (num == 0) {
            return error("删除中存在已确认信息，请取消确认后删除！");
        }
        return toAjax(num);
    }

    //退出
    @GetMapping("/quit")
    public String virtualOrganizeQuit() {
        return prefix + "/virtualOrganizeQuit";
    }

    @PostMapping("/listQuit")
    @ResponseBody
    public TableDataInfo findVirtualQuitList(@RequestParam Map map) {
        return getDataTable(virtualOrganizeService.findVirtualQuitList(map));
    }

    @GetMapping("/addQuit")
    public String addQuit() {
        return prefix + "/addVirtualQuit";
    }

    @PostMapping("/addVirtualQuit")
    @ResponseBody
    public TableDataInfo addVirtualQuit(@RequestParam Map map) {
        return getDataTable(virtualOrganizeService.findVirtualJoinPersonList(map));
    }

    @PostMapping("/addVirtualQuitProcedure")
    @ResponseBody
    public BaseResult addVirtualQuitProcedure(String allEid, String allName) {
        return publicService.procedure(allEid, allName, "eSP_VirtualOrgAddEmp", "2");
    }

    @GetMapping("/editQuit/{id}")
    public String editQuit(@PathVariable("id") String id, ModelMap mmap) {
        mmap.put("editJoin", virtualOrganizeService.findVirtualQuit(id));
        mmap.put("virtualDep", virtualOrganizeService.findVirtualDep());
        mmap.put("virtualJob", virtualOrganizeService.findVirtualJob());
        return prefix + "/editVirtualQuit";
    }

    @PostMapping("/editQuit")
    @ResponseBody
    public AjaxResult editQuit(@RequestParam Map map) {
        return toAjax(virtualOrganizeService.updateVirtualQuit(map));
    }

    @GetMapping("/history")
    public String virtualOrganizeHistory() {
        return prefix + "/virtualOrganizeHistory";
    }

    //历史
    @PostMapping("/history")
    @ResponseBody
    public TableDataInfo virtualOrganizeHistory(@RequestParam Map map) {
        return getDataTable(virtualOrganizeService.findVirtualHistoryList(map));
    }
}
